import request from "@/utils/request";

/**
 * 通知相关接口封装
 */
export const notificationApi = {

  /**
   * 新增通知
   * @param {Object} notification - 通知对象
   * @returns {Promise}
   */
  add: (notification) => {
    return request.post("/notifications/add", notification);
  },

  /**
   * 更新通知
   * @param {Object} notification - 通知对象（必须包含 id）
   * @returns {Promise}
   */
  update: (notification) => {
    return request.post("/notifications/update", notification);
  },

  /**
   * 根据ID删除通知
   * @param {Number} id - 通知ID
   * @returns {Promise}
   */
  deleteById: (id) => {
    return request.delete(`/notifications/${id}`);
  },

  /**
   * 批量删除通知
   * @param {Array<Number>} ids - 要删除的通知ID数组
   * @returns {Promise}
   */
  batchDelete: (ids) => {
    return request.post("/notifications/batch", ids);
  },

  /**
   * 根据ID查询通知详情
   * @param {Number} id - 通知ID
   * @returns {Promise}
   */
  getById: (id) => {
    return request.get(`/notifications/search/${id}`);
  },

  /**
   * 分页查询通知列表（可按接收者ID筛选）
   * @param {Number} receiverId - 接收者ID
   * @param {Number} current - 当前页码
   * @param {Number} size - 每页条数
   * @param {String} status - 状态（0-未读，1-已读，2-已删除）
   * @returns {Promise}
   */
  page: (receiverId, current, size, status) => {
    return request.get("/notifications/page", {
      params: { receiverId, current, size, status }
    });
  },

  /**
   * 查询某用户的未读通知
   * @param {Number} receiverId - 接收者ID
   * @returns {Promise}
   */
  getUnreadByReceiverId: (receiverId) => {
    return request.get(`/notifications/unread/${receiverId}`);
  },

  /**
   * 查询某用户的已读通知
   * @param {Number} receiverId - 接收者ID
   * @returns {Promise}
   */
  getReadByReceiverId: (receiverId) => {
    return request.get(`/notifications/read/${receiverId}`);
  },

  /**
   * 标记通知为已读
   * @param {Number} id - 通知ID
   * @returns {Promise}
   */
  markAsRead: (id) => {
    return request.put(`/notifications/${id}/read`);
  },

  /**
   * 标记通知为已删除（软删除）
   * @param {Number} id - 通知ID
   * @returns {Promise}
   */
  markAsDeleted: (id) => {
    return request.put(`/notifications/${id}/delete`);
  },

  /**
   * 统计某用户的未读通知数量
   * @param {Number} receiverId - 接收者ID
   * @returns {Promise}
   */
  countUnreadByReceiverId: (receiverId) => {
    return request.get(`/notifications/count/unread/${receiverId}`);
  },

  /**
   * 统计某用户的已读通知数量
   * @param {Number} receiverId - 接收者ID
   * @returns {Promise}
   */
  countReadByReceiverId: (receiverId) => {
    return request.get(`/notifications/count/read/${receiverId}`);
  }

};

export default notificationApi;